﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;

namespace NSATBPortal
{
    public partial class TestSetEditAssignments : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            string sVal = Server.UrlDecode(Request.QueryString["Name"].ToString());
            lblParent.Text = "Assignments for " + sVal;

        }

        protected void DefTestSetGrid_RowEditing(object sender, GridViewEditEventArgs e)
        {
            int iIndex = e.NewEditIndex;

            string sRecID = DefTestSetGrid.DataKeys[iIndex].Value.ToString();
            int iTestCaseID = int.Parse(sRecID);
            bool bCheckState = (DefTestSetGrid.Rows[iIndex].Cells[1].Text == "Yes");

            string sVal = Request.QueryString["ID"].ToString();
            int iTestSetID = int.Parse(sVal);

            string sUserID = Request.LogonUserIdentity.Name;
            using (ATBSchemaDB objATBDB = new ATBSchemaDB())
            {
                objATBDB.ModifyDefTestSetAssignment(iTestSetID, iTestCaseID, !bCheckState, sUserID);
            }

            // Update Grid
            if( !bCheckState )
                DefTestSetGrid.Rows[iIndex].Cells[1].Text = "Yes";
            else
                DefTestSetGrid.Rows[iIndex].Cells[1].Text = "";
        }
        protected void DefTestSetGrid_Init(object sender, EventArgs e)
        {
            string sVal = Request.QueryString[0].ToString();
            int iTestSetID = Convert.ToInt32(sVal);

            DataTable dtResults;
            using (ATBSchemaDB objATBDB = new ATBSchemaDB())
            {
                dtResults = objATBDB.GetDefTestSetAssignments(iTestSetID);
            }

            DefTestSetGrid.DataSource = dtResults;
            DefTestSetGrid.DataBind();
        }

    }
}